package com.webwork.lims.system.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.webwork.lims.common.controller.SuperCtrl;
import com.webwork.lims.system.dataobject.Menu;
import com.webwork.lims.system.dataobject.User;
import com.webwork.lims.system.service.MenuService;

@Controller
@RequestMapping(value = "/main")
public class MainController extends SuperCtrl {

	@Autowired
	private MenuService menuSve;
	
	@RequestMapping(value = "getMenuUrl")
	@ResponseBody
	public ResponseEntity<String> getMenuUrl(HttpServletRequest request) {
		HttpHeaders responseHeaders = new HttpHeaders();
		responseHeaders.add("Content-Type", "text/html; charset=utf-8");
		User user = (User) request.getSession(true).getAttribute("user");
		System.out.println(user.getUserId());
		List<Menu> list = menuSve.getMenuByRole(user.getRole());
		return new ResponseEntity<String>(new Gson().toJson(list).toString(), responseHeaders, HttpStatus.CREATED);
	}
	
	@RequestMapping(value = "/welcome")
	@Override
	public String mainPage() {
		return "welcome";
	}
	
}
